<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
  >
    <template #searchPanel>
      <search-panel
        :selectPer="'111'"
        :excelPer="'newCarOrder:export'"
        @search="search"
        @handleDataExport="handleDataExport"
        :showSearchButton="true"
        :showExportButton="true"
        @export="excelInfo"
      >
        <el-select
          clearable
          style="width: 150px"
          v-model="searchOptions.businessType"
          placeholder="业务类型"
        >
          <el-option
            v-for="item in businessTypeOptions"
            :key="item"
            :value="item"
            :label="item"
          />
        </el-select>
        <el-input
          v-model="searchOptions.code"
          clearable
          placeholder="收款单号"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <!-- <el-select
          clearable
          style="width: 150px"
          v-model="searchOptions.carBrandId"
          placeholder="收款项目"
        >
          <el-option
            v-for="item in getDict(['订单状态'])['订单状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select> -->
        <el-input
          v-model="searchOptions.licensePlateNumber"
          clearable
          placeholder="车牌号"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <el-input
          v-model="searchOptions.receiptObjects"
          clearable
          placeholder="收款对象"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <el-input
          v-model="searchOptions.businessCode"
          clearable
          placeholder="业务单号"
          style="width: 150px;margin-bottom: 20px;margin-top: 10px;"
        />
        <el-date-picker
          v-model="searchOptions.receiptDate"
          type="datetimerange"
          start-placeholder="收款开始时间"
          end-placeholder="收款结束时间"
          clearable
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
        />
        <el-date-picker
          v-model="searchOptions.transactionDate"
          type="datetimerange"
          start-placeholder="交易开始时间"
          end-placeholder="交易结束时间"
          clearable
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i title="收款" v-permission="'creditCollection:cancellation'" @click="handleDataDialog(row, '收款')" class="el-icon-money cursor"></i>
          <i title="开票" v-permission="'creditCollection:issue'" class="el-icon-s-order cursor" @click="handleDataDialog(row, '发票信息')"></i>
          <i title="收款历史" v-permission="'creditCollection:history'" @click="handleDataDialog(row, '收款历史')" class="el-icon-refresh-left cursor"></i>
          <i title="完结" v-permission="'creditCollection:beOver'" class="el-icon-success cursor" @click="finish(row)"></i>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-data-form
        v-if="dialogTitle == '收款'"
        :dialogData="selectItemInfo"
        @handleDataOperate="handleDataOperate"
        @close="dialogClose"
      />
      <dialog-invoice-form
        v-if="dialogTitle == '发票信息'"
        :dialogData="selectItemInfo"
        @handleDataOperate="handleDataOperate"
        @close="dialogClose"
      />
      <dialog-history-form
        v-if="dialogTitle == '收款历史'"
        :dialogData="selectItemInfo"
        @handleDataOperate="handleDataOperate"
        @close="dialogClose"
      />
    </template>
  </base-layout>
</template>
<script>
import baseMixin from '@/mixins/base'
import DialogDataForm from './components/DialogDataForm.vue'
import DialogInvoiceForm from './components/DialogInvoiceForm.vue'
import DialogHistoryForm from './components/DialogHistoryForm'
import {
  receiptDueList,
} from '@/api/financial/index'
import { exportExcel } from '@/utils/index'
export default {
  components: { DialogDataForm, DialogInvoiceForm, DialogHistoryForm },
  mixins: [
    baseMixin({
      idName: 'id',
      findData: receiptDueList,
      dataName: ['content', 'totalRecords']
    })
  ],
  data() {
    return {
      tableColumnAttributes: [
        { name: '产生门店', value: 'storeName', type: 'text' },
        { name: '收款单号', value: 'code', type: 'text' },
        { name: '业务类型', value: 'businessType', type: 'text' },
        { name: '客户名称', value: 'customerName', type: 'text' },
        { name: '收款对象', value: 'receiptObjects', type: 'text' },
        { name: '收款金额', value: 'receivedAmount', type: 'text' },
        { name: 'VIN', value: 'vin', type: 'text' },
        { name: '车牌号', value: 'licensePlateNumber', type: 'text' },
        { name: '业务单号', value: 'businessCode', type: 'text' },
        { name: '收款日期', value: 'receiptDate', type: 'text' },
        { name: '收款人', value: 'receiptPerson', type: 'text' },
        { name: '交易日期', value: 'branchOffice', type: 'text' },
        { name: '开票状态', value: 'invoiceStatus', type: 'text' },
      ],
      selectItemInfo: {},
      businessTypeOptions: ['整车贷款','维修收款','装修收款',
      '整车定金','商品定金','对账收款','整车订单款','销售收款','调拨收款','售后定金','挂账结转']
    }
  },
  methods: {
    // 查询
    search() {
      this.currentPage = 1
      this.setTableData()
    },
    //操作项
    handleDataDialog(row, type) {
      this.selectItemInfo = row;
      this.handleDataInsert(type)
    },
    //完结订单
    finish() {
      this.$confirm('确认完结该订单吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // invalid(row.id).then(response => {
        //   if (response.success){
        //     this.$message.success('操作成功');
        //     this.getList();
        //   }
        // })
      })
    },
    //导出
    excelInfo () {
      exportExcel("NewCarOrder", "新车订单(整合)", {}, this.pageSize, this.currentPage);
    },
  },
  async mounted() {}
}
</script>
<style scoped>
  .cursor {
    margin-left: 15px;
    cursor: pointer
  }
</style>
